<style>
.layui-upload-img {
	width: 92px;
	height: 92px;
	margin: 0 10px 10px 0;
}

.authtime-show{
	display:'';
}

.authtime-hidden{
	display:none;
}
</style>
<div class="fsh-rightPanel">
	<blockquote class="site-text layui-elem-quote">
		<h2>新增小程序</h2>
	</blockquote>
	<div class="layui-form" action="">
		<div class="layui-row">
			<div class="fsh-form-lg" id="add_form" style="overflow: hidden;">
				<div class="layui-form-item">
					<label class="layui-form-label"><i>*</i>公司名称</label>
					<div class="layui-input-block">
						<input type="text" name="name" id="add_name"
							lay-verify="required" placeholder="请输入公司名称" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">LOGO</label>
					<div class="layui-input-block">
						<input type="hidden" name="picpath" id="add_picpath" value="">
						<input type="hidden" name="logoMediaId" id="add_logoMediaId"
							value="">
						<div class="layui-upload-drag" id="uploader">
							<i class="layui-icon"></i>
							<p>点击上传，或将文件拖拽到此处</p>
						</div>
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label"><i>*</i>公司地址</label>
					<div class="layui-input-block">
						<input type="text" name="address" id="add_address"
							lay-verify="required" placeholder="请输入公司详细地址" class="layui-input">
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label"><i>*</i>联系人</label>
					<div class="layui-input-block">
						<input type="text" name="linkman" id="add_linkman"
							lay-verify="required" placeholder="请输入联系人姓名" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label"><i>*</i>电话号码</label>
					<div class="layui-input-block">
						<input type="text" name="mobile" id="add_mobile"
							lay-verify="required" placeholder="请输入联系人电话号码"
							class="layui-input">
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label"><i>*</i>是否认证</label>
					<div class="layui-input-block">
						<input type="radio" name="authstatus" lay-filter="add_authed" id='add_authed' value="1" title="已认证" >
						<input type="radio" name="authstatus" lay-filter="add_disauth"  id='add_disauth' value="0" title="未认证" checked="">
					</div>
				</div>
				<div class="layui-form-item authtime-hidden" id="authtimeshow">
					<label class="layui-form-label"><i>*</i>认证时间</label>
					<div class="layui-input-block">
						<input type="text" name="authdate" id="add_authdate"
							lay-verify="date" placeholder="请输入认证时间" autocomplete="off"
							class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">其他执照</label>
					<div class="layui-input-block">
						<div class="layui-upload">
							<button type="button" class="layui-btn" id="licenseBtn">多图片上传</button>
							<div class="layui-upload-list" id="licenseList"></div>
						</div>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">简介</label>
					<div class="layui-input-block">
						<textarea name="description" id="description" cols="100" rows="10"></textarea>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label"></label>
					<div class="layui-input-block">
						<button type="button" class="layui-btn" lay-submit
							lay-filter="addcorp_form">立即提交</button>
						<button type="button" class="layui-btn" id="add_canl">取 消</button>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<script>
	layui.use(
		[ 'layedit', "upload", "form", 'laydate' ],
		function() {
			debugger;
			//var layedit = layui.layedit;
			var $ = layui.$;
			var upload = layui.upload;
			var licenseArray = [];
			var laydate = layui.laydate;
			var form = layui.form;

			form.render();

			//var layeditIndex = layedit.build('content');

			upload.render({
				elem : '#licenseBtn',
				url : '/managerImg/upload2location',
				multiple : true,
				number : 3,
				size : 1024,
				before : function(obj) {
					//预读本地文件示例，不支持ie8
					obj.preview(function(index, file,result) {
						$('#licenseList').append(
							'<img src="'+ result +'" alt="'+ file.name +'" class="layui-upload-img">')
					});
				},
				done : function(res) {
					//上传完毕
					if (res.success) {
						licenseArray.push(res.data);
					} else {
						layer.msg("上传接口异常");
					}

				},
				allDone : function(obj) {
					console.log(obj)
				}
			});

			//取消
			$("#add_canl").click(function() {
				//         	location.href = "/views/index.html#/material/document/document";
				jump("/miniapp/miniaccount/miniaccount");
			});

			//日期
			laydate.render({
				elem : '#add_authdate'
			});
			
			 //选择已认证
			form.on('radio(add_authed)', function(data){
				document.getElementById('authtimeshow').className='layui-form-item authtime-show';
				}); 
			//选择未认证
			form.on('radio(add_disauth)', function(data){
				document.getElementById('authtimeshow').className='layui-form-item authtime-hidden';
				document.getElementById('add_authdate').value='';
				});  

			//提交
			form.on('submit(addcorp_form)',function(d) {
				var formData = d.field;
				var data = {};
				data.name = formData.name;
				data.linkman = formData.linkman;
				data.mobile = formData.mobile;
				data.authstatus = formData.authstatus;
				data.authdate = formData.authdate;
				data.address = formData.address;
				data.licenseList = JSON
						.stringify(licenseArray);
				data.description = formData.description;

				if (data.name == "") {
					layer.msg("请输入公司名称");
					return false;
				}

				if (data.linkman == "") {
					layer.msg("请输入公司联系人");
					return false;
				}

				if (data.mobile == "") {
					layer.msg("请输入联系人电话号码");
					return false;
				}
				ajax({
					url : '/miniAppCorpBaseInfo/save',
					data : data,
					success : function(result) {
						if (result) {
							layer.msg("保存成功");
							setTimeout(function() {
								licenseArray.splice(0,licenseArray.length);//清空数组 
								jump("/miniapp/miniaccount/miniaccount");
							}, 1000);
						}
					},
				});
				return false;
			});
			//上传
			upload.render({
				elem : '#uploader',
				url : '/managerImg/upload2location',
				before : function(obj) {
					showLoading();
					//预读本地文件示例，不支持ie8
					obj.preview(function(index, file,result) {
						$('#uploader').html(
							'<img src="'+ result +'" alt="'+ file.name +'" style="width: 150px;height: 150px;"/>')
					});
				},
				done : function(result) {
					layer.closeAll('loading');
					if (result.success) {
						//$("#uploader").html("<img src='" + result.data + "' style='width: 150px;height: 150px;'/><p>点击重新上传，或将文件拖拽到此处</p>");
						//$("#add_logoMediaId").val(result.data.imgMediaId);
						//$(".wxmp-doclist .main img").attr("src", result.data.url);
						licenseArray.push(result.data);

					} else {
						layer.msg("上传接口异常");
					}
				},
				error : function() {
					layer.closeAll('loading');
					layer.msg(result.msg || "上传接口异常");
				}
			});
		});
</script>